import uniqueId from '@form-create/utils/lib/unique'
import { localeProps } from '../utils'
import { SelectRuleOption } from '../type'
import { selectRule } from '../config/selectRule'
import { cloneDeep } from 'lodash-es'

export const useSelectRule = (option: SelectRuleOption) => {
  const label = option.label
  const name = option.name
  const rules = cloneDeep(selectRule)
  return {
    icon: option.icon,
    label,
    name,
    rule() {
      return {
        type: name,
        field: uniqueId(),
        title: label,
        info: '',
        $required: false,
        props: {
          clearable: true // 默认可清空，该值也会反馈到右侧clearable配置项上
        }
      }
    },
    props(_, { t }) {
      if (!option.props) {
        option.props = []
      }
      return localeProps(t, name + '.props', [
        // makeRequiredRule(),
        ...option.props,
        ...rules
      ])
    }
  }
}
